#!/bin/sh
if [ `id -u` -ne 0 ]; then
  echo You are not root!
  exit 1
fi

iso=$1
dir=$2
argv0=`basename $0`

if [ ! -f "$iso" -o ! -d "$dir" ]; then
  echo usage: $argv0 iso-file mount-point
  exit 1
fi

file $iso | grep -q 'ISO 9660 CD-ROM filesystem data'
if [ $? -ne 0 ]; then
  echo $argv0: $iso is not an ISO 9660 CD-ROM filesystem data
  exit 2
fi

for md in `/sbin/mdconfig -l`; do
  mdx=`/sbin/mdconfig -l -u $md | grep "md.*vnode.*$iso" | awk '{print $1}'`
  if [ ! -z "$mdx" ]; then
    exec /sbin/mount -t cd9660 /dev/$md $dir
  fi
done
md=`/sbin/mdconfig -a -t vnode -f $iso`
exec /sbin/mount -t cd9660 /dev/$md $dir
